package {
	import com.ecity.ctrl.GameController;
	import com.ecity.debug.Debug;
	import com.ecity.events.GameEvent;
	import com.ecity.events.GameState;
	import com.ecity.net.Delegate;
	import com.ecity.util.Samulator;
	import com.ecity.util.UIFactory;
	import com.ecity.view.MainView;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.external.ExternalInterface;
	import flash.text.TextField;
	
	/**
	 * ...
	 * @author yicheng.zhang
	 */
	public class Main extends Sprite {
		private var controller:GameController;
		private var viewer:MainView;
		private var layer:Sprite = new Sprite();
		private var samulator:Samulator = new Samulator();
	
		public function Main():void {
			controller = new GameController();
			viewer = new MainView();
			layer.addChild(samulator);//===========================
			this.addChild(viewer);
			this.addChild(layer);
			samulator.addEventListener(GameEvent.SAMULATOR_CLICK, onSamulatorClick);
		}
		
		private function onSamulatorClick(e:GameEvent):void {
			viewer.hitTestCase(tx, ty);
			//trace(e._info.mx, " , ", e._info.my);
		}
		
		private function initCaller():void {
			try {
				ExternalInterface.addCallback("iCall", iCall);
			} catch (error:SecurityError) {
			} catch (error:Error) {
			}
		}
		
		private function onResourceComplete(e:GameEvent):void {
			viewer.startGame();
			groupButton();
			initGrid();
			GameState.hitable = true;
			GameState.state = GameState.GAME_READY;
		}
		
		public function iCall(param: String):String {
			var p:Array = param.split('|');
			var pos:Array;
			var tx:int;
			var ty:int;
			for (var i:int = 0; i < p.length; i ++){
				pos = p[i].split(',');
				tx = pos[0];
				ty = pos[1];
			}
			return "";
		}
		

	}		
	
}